From: | Laura Vance |
Date: | 24 Aug 99 at 18:40:20 |
Subject: | Re: Text Boxes |
From: Laura Vance <vancel@amiga.nols.com>
On Tue, 24 Aug 1999 17:28:49,
andrewmarkwell@ukonline.co.uk wrote about Re: [amiga-c] Text Boxes:
>From: andrewmarkwell@ukonline.co.uk
>
>>From: Laura Vance <vancel@amiga.nols.com>
>>
>>Hi again,
>>I have made a program that uses a separate window to display some text.
>>The text is too long to fit on one line in a window, and it looks nicer to
>>have it wrap around the edge for another line. I couldn't find a text box
>>style gadget within the system libraries (one might be there, but I didn't
>>find it) I tried making a regular text box from the gadtools.library large
>>enough to hold it, but all the larger text box did was still let the text
>>flow out of the other side. I wrote a small function to count the
>>characters based on the width of the font and try to wrap them at the
>>appropriate time, and it works with some fonts, but I would prefer to let
>>the system handle that.
>
>
>
>
>You could try making each word a separate IntuiText. Then work out
>
>separately where to position each word. The functions IntuiTextLength()
>and PrintIText will be useful. You can work out font heights from
>IntuiText->ITextFont->ta_YSize.
>
>Andrew Markwell
>
And that's what I've been doing that I want to get away from. The function
that I wrote was was as follows:
- The Window structure is the window where the text will be displayed (I
get the rastport from this structure.
- The Gadget structure is when I decided to use a TEXT_KIND gadget and just
get the sizes from the borders of the gadget instead of having to pass all
4 edges into the function.
- The *text is the actual text that is going to be output/formatted to the
window's area.
- The short top and short left are the top left corner of the gadget/area
that the text needs to fit into.
- I made use of some of my global variables that were useless at this point
in the program also.
- I think this version of the function returns the text to the program with
all of the appropriate '/n' inserted and the other part of the program uses
the text as it sees fit. (whether in a PrintIText() or whatever).
char * fittextwin(struct Window *win, struct Gadget *gad, char *text, short
top, short left)
{
short line = 1, ctr, fontsize, ctr2 = 0, maxwide = 0, pixels, adjust =
15, temp, temp2;
char *cardtext = "hi there";
pixels = TextLength(win->RPort,text,strlen(text));
pixels = pixels - (win->Width - gad->Width);
maxwide = (gad->Width / (pixels / strlen(text))) - adjust;
fontsize = mytextattr.ta_YSize + 2;
for(ctr=0; ctr<=strlen(text); ctr++)
{
cardtext[ctr2++] = text[ctr];
if((ctr>line*maxwide && text[ctr] == ' ')|| ctr == strlen(text))
{
temp = ctr;
temp2 = ctr2;
while(text[temp] != ' ')
{
temp++;
cardtext[temp2++] = text[temp];
if(ctr > maxwide + adjust)
{
ctr = temp;
ctr2 = temp2;
break;
}
}
cardtext[ctr2-1] = NULL;
tarotext.IText = cardtext;
PrintIText(win->RPort,&tarotext,top,left+line * fontsize);
line++;
ctr2 = 0;
}
}
return(cardtext);
}
If anyone wants to see the actual program where I use this, just let me
know. It's called "AmiTarot" and it can be found on Aminet, but I don't
know if they have the most recent version. i.e. I don't know if it has the
mild graphics that I've started using. If anyone wants it, you can email
me directly and I will gladly send the archive to you.
Laura